package com.etime.yqtsponsor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.etime.yqtsponsor.dao.UserBehaviorMapper;
import com.etime.yqtsponsor.dto.VoteRegisterDto;
import com.etime.yqtsponsor.pojo.UserBehavior;
import com.etime.yqtsponsor.service.UserBehaviorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

/**
 * @author ly
 * @date 2022/7/19 20:17
 */
@Service
public class UserBehaviorServiceImpl implements UserBehaviorService {


    @Autowired
    private UserBehaviorMapper userBehaviorMapper;

    /**
     * 删除活动时，同步删除选手行为记录
     * @param activeId
     * @return
     */
    @Override
    public int deleteUserByActiveId(Integer activeId) {
        return userBehaviorMapper.deleteParticipator(activeId);
    }

    /**
     * 删除选手时，同步删除选手行为记录
     * @param registerId
     * @return
     */
    @Override
    public int deleteRegister(Integer registerId) {
        UserBehavior userBehavior = new UserBehavior();
        userBehavior.setDeleted(1);
        QueryWrapper<UserBehavior> wrapper = new QueryWrapper<>();
        wrapper.eq("registerId",registerId);
        wrapper.eq("type",2);
        return userBehaviorMapper.update(userBehavior,wrapper);
    }

    @Override
    public Page<UserBehavior> selectBehaviorByActiveId(Integer id,Long pageNum, Long pageSize) {
        Page<UserBehavior> page;
        if (pageNum != null && pageSize != null) {
            page = new Page<>(pageNum, pageSize);
        } else {
            page = new Page<>();
        }
        QueryWrapper<UserBehavior> wrapper = new QueryWrapper<>();
        wrapper.eq("activeId",id);
        wrapper.eq("type", 2);
        return userBehaviorMapper.selectByActiveId(page,wrapper);
    }

    /**
     * 根据组件查找选手行为信息
     * 删除活动组时需要验证该组是否存在报名选手
     * @param id
     * @return
     */
//    @Override
//    public UserBehavior selectByActiveId(Integer id) {
//        return userBehaviorMapper.selectByActiveId(id);
//    }
}
